package com.yxw.live_vod_backend_boot.controller;

import com.yxw.live_vod_backend_boot.dto.ReviewExamineDTO;
import com.yxw.live_vod_backend_boot.dto.ShopReviewDTO;
import com.yxw.live_vod_backend_boot.dto.ShopReviewQueryDTO;
import com.yxw.live_vod_backend_boot.service.ShopReviewService;
import com.yxw.live_vod_backend_boot.vo.ShopReviewVO;
import com.yxw.live_vod_facade.dto.ShopExtendAddDTO;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.helper.ResultHelper;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 店铺审核管理 Controller控制层
 *
 * @author xiexuxin
 * @date 2023-11-28
 */
@RestController
@Api(value = "店铺审核管理", tags = "店铺审核管理")
@Slf4j
@RequestMapping("/api/shop_review")
public class ShopReviewController {

    @Autowired
    private ShopReviewService shopReviewService;

    @ApiOperation("添加店铺审核数据")
    @PostMapping("add_shop_review")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "form",name = "corporateCardFront", value = "法人身份证正面照片", required = true, dataType = "__file"),
            @ApiImplicitParam(paramType = "form",name = "corporateCardReverse", value = "法人身份证反面照片", required = true, dataType = "__file"),
            @ApiImplicitParam(paramType = "form",name = "corporateCardHand", value = "法人手持身份证照片", required = true, dataType = "__file"),
            @ApiImplicitParam(paramType = "form",name = "shopAvatar", value = "店铺头像", required = true, dataType = "__file"),
            @ApiImplicitParam(paramType = "form",name = "businessLicense", value = "营业执照照片", required = true, dataType = "__file")
    })
    public BaseResult addShopReview(@RequestParam("corporateCardFront") MultipartFile corporateCardFront,
                                    @RequestParam("corporateCardReverse") MultipartFile corporateCardReverse,
                                    @RequestParam("corporateCardHand") MultipartFile corporateCardHand,
                                    @RequestParam("shopAvatar") MultipartFile shopAvatar,
                                    @RequestParam("businessLicense") MultipartFile businessLicense,
                                    @ModelAttribute ShopReviewDTO addDTO) {
        ShopReviewVO vo = shopReviewService.addShopReview(corporateCardFront, corporateCardReverse, corporateCardHand, shopAvatar, businessLicense, addDTO);
        return BaseResult.doSuccess(vo, "添加店铺审核数据成功");
    }

    @ApiOperation("修改店铺审核数据")
    @PostMapping("update_shop_review")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "form",name = "corporateCardFront", value = "法人身份证正面照片", required = false, dataType = "__file"),
            @ApiImplicitParam(paramType = "form",name = "corporateCardReverse", value = "法人身份证反面照片", required = false, dataType = "__file"),
            @ApiImplicitParam(paramType = "form",name = "corporateCardHand", value = "法人手持身份证照片", required = false, dataType = "__file"),
            @ApiImplicitParam(paramType = "form",name = "shopAvatar", value = "店铺头像", required = false, dataType = "__file"),
            @ApiImplicitParam(paramType = "form",name = "businessLicense", value = "营业执照照片", required = false, dataType = "__file")
    })
    public BaseResult updateShopReview(@RequestParam(value = "corporateCardFront", required = false) MultipartFile corporateCardFront,
                                       @RequestParam(value = "corporateCardReverse", required = false) MultipartFile corporateCardReverse,
                                       @RequestParam(value = "corporateCardHand", required = false) MultipartFile corporateCardHand,
                                       @RequestParam(value = "shopAvatar", required = false) MultipartFile shopAvatar,
                                       @RequestParam(value = "businessLicense", required = false) MultipartFile businessLicense,
                                       @RequestParam("shopReviewId") Long shopReviewId,
                                       @ModelAttribute ShopReviewDTO updateDTO) {
        shopReviewService.updateShopReview(corporateCardFront, corporateCardReverse, corporateCardHand, shopAvatar, businessLicense, shopReviewId, updateDTO);
        return BaseResult.success();
    }

    @ApiOperation("根据id查询店铺审核数据详情")
    @PostMapping("get_shop_review_by_id")
    public BaseResult getShopReviewById(@RequestParam("shopReviewId") Long shopReviewId) {
        ShopReviewVO vo = shopReviewService.getShopReviewById(shopReviewId);
        return BaseResult.doSuccess(vo,"查询成功");
    }

    @ApiOperation("根据店铺id查询店铺审核数据详情")
    @PostMapping("get_shop_review_by_shop_id")
    public BaseResult getShopReviewByShopId(@RequestParam("shopId") Long shopId) {
        ShopReviewVO vo = shopReviewService.getShopReviewByShopId(shopId);
        return BaseResult.doSuccess(vo,"查询成功");
    }

    @ApiOperation("获取店铺审核数据列表")
    @PostMapping("get_shop_review_list")
    public BaseResult<PageVO<ShopReviewVO>> getShopReviewList(@RequestBody ShopReviewQueryDTO queryDTO) {
        PageVO<ShopReviewVO> pageVO = shopReviewService.getShopReviewList(queryDTO);
        return ResultHelper.fillWithSuccess(pageVO);
    }

    @ApiOperation("店铺具体审核")
    @PostMapping("is_shop_review")
    public BaseResult isShopReview(@RequestBody @Validated ReviewExamineDTO examineDTO) {
        BaseResult shopReview = shopReviewService.isShopReview(examineDTO);
        return BaseResult.doSuccess(shopReview,"审核完成");
    }

    @ApiOperation("添加店铺扩展信息")
    @PostMapping("add_shop_extend")
    public BaseResult addShopExtend(@RequestBody @Validated ShopExtendAddDTO extendAddDTO) {
        shopReviewService.addShopExtend(extendAddDTO);
        return BaseResult.doSuccess(null,"添加完成");
    }

    @ApiOperation("修改店铺状态")
    @PostMapping("update_shop_status")
    public BaseResult updateShopStatus(@RequestParam("shopId") Long shopId, @RequestParam("status") Integer status) {
        shopReviewService.updateShopStatus(shopId, status);
        return BaseResult.doSuccess(null,"修改完成");
    }

}
